﻿using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using groupAnalyzer.Observers;

namespace groupAnalyzer
{
    /// <summary>
    /// Interaction logic for AdsTree.xaml
    /// </summary>
    public partial class AdsTree : Window
    {
        private ViewFactory viewFactory;
        private Searcher searcher;

        public AdsTree(ViewFactory viewFactory, Searcher searcher)
        {
            InitializeComponent();

            this.viewFactory = viewFactory;
            this.searcher = searcher;

            Collection<BaseView> rootNode = this.viewFactory.Tree;
            this.adsTree.ItemsSource = rootNode;
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            object groupView = this.adsTree.SelectedItem;
            if (typeof(GroupView) == groupView.GetType())
            {
                this.searcher.refreshBinding((GroupView)groupView,true);
                this.Close();
            }
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            // just close the window and do nothing...
            this.Close();
        }
    }
}
